Repository navigation
fix(policies): start a policy's handlers before its new inputs - #801
Conversation
PolicyManager::load started each new input stream's -resources policy before the policy itself, and starting the resources policy started the input. An input that reads all its data as it starts, such as a pcap_file, was then consumed before the policy's handlers were connected, so the policy saw nothing: a 140-packet capture counted 0. The resources policies are now created after the policy has started its handlers and then its inputs. Policy::start also stops the handlers it started when a later handler or input fails, because a sequence handler cannot be removed while the next one is still connected to it; without that, a failed load left the policy's handlers registered and every retry got "already exists". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Summary — No new commits since the last review. Correctness and security were re-checked against the current head; no new findings. Net-positive fix. Both findings from the previous review were declined by the author with concrete reasoning tied to the code (one already marked dismissed; the other newly declined in the PR conversation). Independent re-verification agrees neither is a live bug, so neither is being re-raised. 🤖 AI Code Review · run · prompts: Previous review · 2026-10-28 · 5f9d5e5AI Code Review — risk tier: Advisory only. A human owns the merge decision. Summary — Net-positive fix: reorders handler/input startup so a policy's handlers are connected before its inputs run, with a rollback path for partial starts, and includes regression tests for both the original bug and the new failure mode. One small gap remains in the new rollback logic for multi-tap policies. Findings
🤖 AI Code Review · run · prompts: Previous review · 2026-10-28 · cd73275AI Code Review — risk tier: Advisory only. A human owns the merge decision. Summary — Net-positive fix: reordering policy start (handlers before inputs, resources-policy after) correctly resolves the described pcap_file/dnstap_file race, and the new Pre-existing / out-of-scope
🤖 AI Code Review · run · prompts: |
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cd73275e42
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
LCOV of commit
|
The previous commit started the policy's handlers before its new inputs, but created the resources policies afterwards, so for a pcap_file or dnstap_file input the resources handler connected only after the whole file had been read and recorded no CPU or memory samples. The resources handlers are now created, registered and started before the policy starts its inputs, and the resources policies are started and registered once the inputs run. Registering the handler before the policy also closes the window where a failed handler registration left a policy pointing at a destroyed handler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
|
AI review finding "Rollback of partially-created resources policies leaves a dangling policy pointer on the shared input": won't do here, because it can't happen in this code.
The dangling pointer that does matter, on a reused input when a load fails before the policy has started, is the separate pre-existing issue listed in the description. |
|
/ai-review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
/ai-review |
|
AI review finding "Policy::start() rollback doesn't stop already-started inputs on a multi-tap policy": won't do. The inputs it describes are already stopped, and the suggested change would break shared inputs.
|
|
/ai-review |
|
🔁 AI Code Review updated for |
Summary
A policy on a
pcap_filetap saw none of its packets in pktvisord. In the orb-agent lab for MON-444, a 140-packet capture applied through the admin API counted 0 in both the net and dns handlers, and nothing was exported.Cause.
PolicyManager::loadcreated and started each new input stream's<stream>-resourcespolicy before it started the user's policy. Starting the resources policy started the input.Policy::start()starts its handlers before its inputs, but by then the input had already run. Apcap_file, and adnstap_file, is read whole insidestart(), so it was consumed before the user's handlers were connected. A live interface lost only its first milliseconds, which is why this went unnoticed.Fix.
Order: every handler on a new input now runs before the input starts.
create_resources_policycreates, registers and starts the resources handler, but not the resources policy.policy_ptr->start()starts the user's handlers and then the inputs.start()returns early when already running.Both the user's handlers and the resources handler see the whole file.
Rollback:
Policy::start()now stops the handlers it started when a later handler or input fails.Tidying:
create_resources_policynow returns the unstarted resources policy, and it lost its unusedpolicy_nameparameter. Errors are wrapped once by the caller, so messages are unchanged. The resources handler is registered before its policy, which closes a window where a failed handler registration left a registered policy pointing at a destroyed handler.Tests
Good Config pcap_file input feeds the policy's handlers: apcaptap ontests/fixtures/dns_ipv4_udp.pcapand anetpolicy.0 == 140).null != nullptr).Bad Config: exception on input start with sequence modules: apcaptap with a missingpcap_fileand sequence modules[dns, net]. Two loads must both fail withpolicy [broken_view] failed to start: Cannot open pcap/pcapng file, leaving no policy or handler behind. Without thePolicy::start()rollback it failed with "unable to remove, handler has consumers".pcap_file: the policy counts net 140 and dns 140 (70 queries, 70 replies), against 0 on develop. A DELETE and re-POST counts 140 again. The resources policy recordscpu_usageandmemory_bytessamples.Not addressed here (found in review, all older than this change)
loadtakes the input map and then the policy map, whileremove_policytakes them the other way round, so a concurrent POST and DELETE can deadlock. This change shortens the window: an input'sstart()no longer runs while the input map lock is held.load: it catchesstd::runtime_erroronly. Astd::logic_error, such as PcapPlusPlus'sstd::invalid_argument, skips the rollback. With this change the leftover handlers are at least stopped.PcapInputStream::start()assigns theifacestring to anIPv4Addressand anIPv6Address, and 25.05 throws on anything that isn't an address, soiface: eth0gives "Not a valid IPv4 address: eth0". Seen in the orb-agent develop image on Linux and on macOS builds. It is unrelated to this change and needs its own fix.🤖 Generated with Claude Code